package tv.scolopender.fragment;

import java.util.ArrayList;

import tv.scolopender.R;
import tv.scolopender.adapter.ScoloArrayAdapter;
import tv.scolopender.application.ScoloApp;
import tv.scolopender.asynctask.ScoloBestAsyncTask;
import tv.scolopender.listener.ScoloListScrollListener;
import tv.scolopender.model.Scolo;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

public class NewsSectionFragment extends Fragment {
	private int totalScolos;
	private ArrayList<Scolo> scolos;

	public NewsSectionFragment() {
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		scolos = ((ScoloApp) getActivity().getApplication()).getScolos();
		totalScolos = scolos.size();
		View rootView = inflater.inflate(R.layout.fragment_swipe_main_scolo,
				container, false);
		ListView scoloList = (ListView) rootView.findViewById(R.id.scoloList);

		ScoloArrayAdapter scoloAdapter = new ScoloArrayAdapter(getActivity(),
				R.layout.listitem_scolo, scolos);

		ScoloBestAsyncTask asyncTask = new ScoloBestAsyncTask(getActivity(),
				scoloAdapter);

		scoloList.setAdapter(scoloAdapter);
		scoloList.setOnScrollListener(new ScoloListScrollListener(scolos,
				getActivity(), asyncTask));

		return rootView;
	}
}
